package com.example.lc.baidumapradiobutton;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.RadioButton;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        RadioButton button=(RadioButton) findViewById(R.id.button1);
        Drawable drawable=getResources().getDrawable(R.drawable.image_radio_button_sel);
        drawable.setBounds(0,0,dip2px(this,80),dip2px(this,60));
        button.setCompoundDrawables(null,drawable,null,null);

        RadioButton button2=(RadioButton) findViewById(R.id.button2);
        Drawable drawable2=getResources().getDrawable(R.drawable.vector_radio_button_sel);
        drawable2.setBounds(0,0,dip2px(this,80),dip2px(this,60));
        button2.setCompoundDrawables(null,drawable2,null,null);
    }

    /**
     *pix和dp转换器
     */
    public static int dip2px(Context context, float dipValue) {

        final float scale = context.getResources().getDisplayMetrics().density;

        return (int) (dipValue * scale + 0.5f);

    }
}
